home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / PART_F / VIEWMAN / WINDOWS.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  21.3 KB  |  913 lines

  1. /* WINDOWS.C
  2.  * ================================================================
  3.  * DATE: October 17, 1990
  4.  * DESCRIPTION: 
  5.  */
  6. #include <sys\gemskel.h>
  7. #include <string.h>
  8. #include <tos.h>
  9. #include <vdikeys.h>
  10.  
  11. #include <stdio.h>
  12.  
  13. #include "viewer.h"
  14. #include "DaveStuf.h"
  15. #include "mainstuf.h"
  16.  
  17. /*
  18.  * TURN OFF Turbo C "parameter X is never used" warnings
  19.  */
  20. #pragma warn -par
  21.  
  22.  
  23.  
  24. /* DEFINES
  25.  * ================================================================
  26.  */
  27. #define DUMMY        4    /* just a random number for window offsets(pixels) */
  28. #define NO_WINDOW   ( -1 )
  29. #define WKIND        ( INFO | NAME | FULLER | MOVER | SIZER | UPARROW | DNARROW | VSLIDE | LFARROW | RTARROW | HSLIDE )
  30. #define BSIZE        16
  31.  
  32. #define WORLD       0
  33. #define LIBRARY       1
  34.  
  35. typedef struct _wdata
  36. {
  37.     int xoffset;        /* Xoffset in window (pixels ) */
  38.     int yoffset;        /* Yoffset in window (pixels ) */
  39.     unsigned int w_wid;        /* Width of form           */
  40.     unsigned int w_hite;    /* Height of form           */
  41.     GRECT  w;            /* GRECT of work window           */
  42. }WDATA;
  43.  
  44.  
  45.  
  46.  
  47. /* PROTOTYPES
  48.  * ================================================================
  49.  */
  50. void DaveName( int id, char *name );
  51.  
  52. void slider_chk( void );
  53. int  scale( int visible, int factor, int total );
  54. void sliderv( void );
  55. void sliderh( void );
  56.  
  57. void nada( void );
  58. void wupline( void );
  59. void wdnline( void );
  60. void wrtline( void );
  61. void wlfline( void );
  62.  
  63. void Full_Window( void );
  64. void Do_Arrows( int action );
  65. void HSlide_Window( int position );
  66. void VSlide_Window( int position );
  67. void Size_Window( GRECT *rect );
  68. void Move_Window( GRECT *rect );
  69.  
  70. int  Check_ID( int id );
  71. void SetDave_Stuff( int handle );
  72. void Set_Window_To_Size( int width, int height );
  73. void DaveInfo( int id, char *name );
  74. void Update_World( int handle );
  75.  
  76. void Gem_Exit( int code );
  77. int  GetTopWindow( void );
  78. void do_arrow_buttons( int key );
  79.  
  80. /* EXTERN
  81.  * ================================================================
  82.  */
  83.  
  84.  
  85. /* GLOBALS 
  86.  * ================================================================
  87.  */
  88.  
  89. /*-----------------------------------------------------------------
  90.  * Window Structure variables 
  91.  *----------------------------------------------------------------- 
  92.  */
  93. WINFO  *W;                 /* Global Window ptr */
  94. WINFO  w;                /* WORLD FORM Window structure  */
  95. WINFO  l;                /* Library WiNdOw Structure     */
  96. WINFO *window[2];            /* Window array            */
  97.  
  98. WDATA wstruct[2];            /* Array data Cary<->Dave which 
  99.                      * replaces the globals defined
  100.                      * for the same info. ( DAVE )
  101.                      */
  102.  
  103.  
  104. /*-----------------------------------------------------------------
  105.  * Global Window Offsets and Form Width and Heights.
  106.  * These are used to point to the actual values.
  107.  *-----------------------------------------------------------------
  108.  */
  109. int  *XOFFSET;
  110. int  *YOFFSET;
  111. unsigned int  *FORM_WIDTH;
  112. unsigned int  *FORM_HEIGHT;
  113.  
  114. int  Cur_Handle;            /* Current Handle - WORLD | LIBRARY */
  115. GRECT Grid;                /* Grid Dialog Box Global ( DAVE )*/
  116. GRECT Old_Lib;                /* Old Library Curr window grect  */
  117.  
  118. /*----------------------------------------------------------------------
  119.  * Arrow function pointers used by the slider routines.
  120.  *----------------------------------------------------------------------
  121.  */
  122. void (*arrow_funcs)( void );        /* These are used by the arrow      */
  123. void (*slide_arrow)( void );        /* and slider routines for scrolling*/
  124.  
  125.  
  126.  
  127.  
  128. /* FUNCTIONS
  129.  * ================================================================
  130.  */
  131.  
  132. /* wind_init()
  133.  * ================================================================
  134.  */
  135. void
  136. wind_init( void )
  137. {
  138.    int     i;
  139.    WINFO   *x;
  140.    int     flag;
  141.    
  142.    window[ WORLD ]   = &w; 
  143.    window[ LIBRARY ] = &l;
  144.    
  145.    for( i = LIBRARY; i >= WORLD; i-- )
  146.    {
  147.       x = window[i];
  148.       
  149.       x->kind   = WKIND;
  150.       x->id     = NO_WINDOW;
  151.       x->wchar  = gl_wbox;
  152.       x->hchar  = gl_hbox;    
  153.       x->fulled = FALSE;
  154.  
  155.       if( ( x->id = Wind_create( x->kind, &desk )) < 0 )
  156.       {
  157.          x->id = NO_WINDOW;
  158.          wind_exit();
  159.          form_alert( 1, "[1][ No More Windows| Available. Problems...][ Sorry ]");
  160.          return;    
  161.       }        
  162.  
  163.  
  164.  
  165.       /* The world window will be 3/4 of the width of the screen
  166.        * -------------------------------------------------------
  167.        */
  168.       if( i == WORLD )
  169.       {
  170.          strcpy( x->name, " ViewMaster " );
  171.          strcpy( x->info, " " );
  172.       }
  173.       
  174.       
  175.       /* The Library window will be 1/4 of the width of the screen
  176.        * -------------------------------------------------------
  177.        */
  178.       if( i == LIBRARY )
  179.       {
  180.          strcpy( x->name, " World Info " );
  181.          strcpy( x->info, " " );
  182.       }
  183.       Wind_calc( 1, x->kind, &x->r, &x->work );
  184.       
  185.       if( i == LIBRARY )        /* Used for Full Box of Library window */
  186.          Old_Lib = x->r;
  187.          
  188.       wind_set( x->id, WF_NAME, x->name );
  189.       wind_set( x->id, WF_INFO, x->info );      
  190.       Wind_open( x->id, &x->r );
  191.    }
  192.    
  193.    /* We want the WORLD window to be on top */
  194.    wind_set( window[ WORLD ]->id, WF_TOP );
  195.  
  196.    Update_World( WORLD );
  197.    Update_World( LIBRARY );
  198.       
  199.    
  200.    flag = DaveInit( Brush_Path );
  201.    while( !flag || ( flag == -1 ) )
  202.    {
  203.        /* Brushes exist, but several errors occurred */
  204.        if( flag == -1 )
  205.        {
  206.           if( form_alert( 1, "[1][ | | Brush File(s) Error!  | Write the Error File?  ][ OK | Cancel ]") == 1 )
  207.           {  
  208.             SaveErr();
  209.           }
  210.           flag = TRUE; /* forces it to exit */
  211.        }
  212.        
  213.        
  214.        if( !flag )
  215.        {
  216.           if( form_alert( 1,"[1][ |  No Brushes Found!   ][Try Again|Exit]") == 1 )
  217.           {
  218.             Set_Brush_Path();
  219.             flag = DaveInit( Brush_Path );
  220.           }
  221.           else
  222.           {
  223.             Gem_Exit( -1 );
  224.           }  
  225.        }
  226.    }
  227.    vex_butv( vhandle, NEW_BUT, ( int (**)() )&BUT_ADDR );
  228.  
  229.    World_Check();
  230.    
  231.    SetDave_Stuff( LIBRARY );
  232.    slider_chk();
  233.  
  234.    SetDave_Stuff( WORLD );
  235.    slider_chk();
  236. }
  237.  
  238.  
  239.  
  240.  
  241. /* do_windows()
  242.  * ================================================================
  243.  */
  244. void
  245. do_windows( int *msg, int *event )
  246. {
  247.     int handle;
  248.     
  249.     if( ( handle = Check_ID( msg[3] )) == NO_WINDOW )
  250.           return;
  251.  
  252.     SetDave_Stuff( handle );     
  253.         
  254.     switch( msg[0] )
  255.     {
  256.        case WM_REDRAW: do_redraw( handle, ( GRECT *)&msg[4] );
  257.                       break;
  258.  
  259.        case WM_NEWTOP:
  260.        case WM_TOPPED: wind_set( W->id, WF_TOP );
  261.                       break;
  262.                       
  263.        case WM_FULLED: Full_Window();
  264.                       break;
  265.                       
  266.        case WM_ARROWED:Do_Arrows( msg[4] );
  267.                       break;
  268.  
  269.        case WM_HSLID:  HSlide_Window( msg[4] );
  270.                       break;
  271.  
  272.        case WM_VSLID:  VSlide_Window( msg[4] );
  273.                       break;
  274.  
  275.        case WM_SIZED:  Size_Window( ( GRECT *)&msg[4] );
  276.                       break;
  277.  
  278.        case WM_MOVED:  Move_Window( ( GRECT *)&msg[4] );
  279.                       break;
  280.        default:  
  281.                break;
  282.     }   
  283.  
  284. }
  285.  
  286.  
  287.  
  288.  
  289.  
  290. /* Full_Window()
  291.  * ================================================================
  292.  */
  293. void
  294. Full_Window( void )
  295. {
  296.    GRECT prev;
  297.    GRECT full;
  298.    GRECT curr;
  299.  
  300.    Wind_get( W->id, WF_CURRXYWH, ( WARGS *)&curr );
  301.    Wind_get( W->id, WF_FULLXYWH, ( WARGS *)&full );
  302.  
  303.  
  304.    /* The Library window will just toggle between the library world size
  305.     * and the previous size. The WORLD window will size to FULL and
  306.     * previous size.
  307.     */  
  308.    if( Cur_Handle == LIBRARY )
  309.    {
  310.       Wind_get( 0, WF_WORKXYWH, ( WARGS *)&full );
  311.       
  312.       wstruct[ LIBRARY ].xoffset = 0;
  313.       wstruct[ LIBRARY ].yoffset = 0; 
  314.       
  315.       if(( wstruct[ LIBRARY ].w_wid  == W->work.g_w ) &&
  316.          ( wstruct[ LIBRARY ].w_hite == W->work.g_h ) )
  317.       { 
  318.           W->r = Old_Lib; /* Go back to the old size window...*/
  319.       }
  320.       else
  321.       {
  322.           W->work.g_w = wstruct[ LIBRARY ].w_wid; 
  323.           W->work.g_h = wstruct[ LIBRARY ].w_hite;
  324.           Wind_calc( 0, W->kind, &W->work, &W->r );
  325.       }
  326.       W->r.g_x = max( W->r.g_x, full.g_x );
  327.       W->r.g_y = max( W->r.g_y, full.g_y );
  328.       W->r.g_w = min( W->r.g_w, full.g_w );
  329.       W->r.g_h = min( W->r.g_h, full.g_h );
  330.       Wind_set( W->id, WF_CURRXYWH, ( WARGS *)&W->r );    
  331.       Wind_calc( 1, W->kind, &W->r, &W->work );
  332.       Wind_set( W->id, WF_WORKXYWH, ( WARGS *)&W->work );
  333.    }
  334.    else
  335.    {   /* WORLD WINDOW Full size box handling */
  336.      if( rc_equal( &curr, &full ) )
  337.      {
  338.        Wind_get( W->id, WF_PREVXYWH, ( WARGS *)&prev );
  339.        Graf_shrinkbox( &prev, &full );
  340.        Wind_set( W->id, WF_CURRXYWH, ( WARGS *)&prev );
  341.        W->fulled = FALSE;
  342.      }
  343.      else
  344.      {
  345.        Graf_growbox( &curr, &full );
  346.        Wind_set( W->id, WF_CURRXYWH, ( WARGS *)&full );
  347.        W->fulled = TRUE;
  348.      }
  349.      DisplayXY();
  350.    }                      
  351.  
  352.  
  353.    Wind_get( W->id, WF_CURRXYWH, ( WARGS *)&W->r );
  354.    Wind_get( W->id, WF_WORKXYWH, ( WARGS *)&W->work );
  355.    Update_World( Cur_Handle );                    
  356.    slider_chk();
  357. }
  358.  
  359.  
  360.  
  361.  
  362. /* Do_Arrows()
  363.  * ================================================================
  364.  */
  365. void
  366. Do_Arrows( int action )
  367. {
  368.    MRETS m;
  369.  
  370.       arrow_funcs = nada;
  371.       slide_arrow = sliderv;
  372.       
  373.       switch( action )
  374.       {
  375.     case WA_UPPAGE:  *YOFFSET = max( *YOFFSET - W->work.g_h, 0 );
  376.              sliderv();
  377.              if( Cur_Handle == WORLD );
  378.                  DisplayXY();
  379.  
  380.              do_redraw( Cur_Handle, &W->work );
  381.              break;
  382.                              
  383.     case WA_DNPAGE:  if( *FORM_HEIGHT > W->work.g_h )
  384.              {
  385.                *YOFFSET += W->work.g_h;
  386.                *YOFFSET  = min( *YOFFSET, *FORM_HEIGHT - W->work.g_h );
  387.                sliderv();
  388.                if( Cur_Handle == WORLD );
  389.                   DisplayXY();
  390.                do_redraw( Cur_Handle, &W->work );
  391.              }
  392.              break;
  393.                          
  394.     case WA_UPLINE:  if( ( *FORM_HEIGHT > W->work.g_h ) && *YOFFSET )
  395.              {
  396.                 *YOFFSET = max( *YOFFSET - BSIZE, 0 );
  397.                 arrow_funcs = wupline;
  398.              }  
  399.              break;
  400.                                
  401.     case WA_DNLINE:  if( *FORM_HEIGHT > W->work.g_h )
  402.              {
  403.                 if( *YOFFSET < ( *FORM_HEIGHT - W->work.g_h ) )
  404.                 {
  405.                   *YOFFSET += BSIZE;
  406.                   *YOFFSET = min( *YOFFSET, *FORM_HEIGHT - W->work.g_h );    
  407.                   arrow_funcs = wdnline;
  408.                 }  
  409.              }
  410.              break;
  411.                          
  412.     case WA_LFPAGE:  *XOFFSET = max( *XOFFSET - W->work.g_w, 0 );
  413.              sliderh();
  414.              if( Cur_Handle == WORLD );
  415.                 DisplayXY();
  416.              do_redraw( Cur_Handle, &W->work );
  417.              break;
  418.                                   
  419.     case WA_RTPAGE:  if( *FORM_WIDTH > W->work.g_w )
  420.              {
  421.                 *XOFFSET += W->work.g_w;
  422.                 *XOFFSET = min( *XOFFSET, *FORM_WIDTH - W->work.g_w );
  423.                 sliderh();
  424.                 if( Cur_Handle == WORLD );
  425.                   DisplayXY();
  426.                 do_redraw( Cur_Handle, &W->work );
  427.              }
  428.              break;
  429.                          
  430.     case WA_LFLINE:  if( *FORM_WIDTH > W->work.g_w )
  431.              {
  432.                 *XOFFSET = max( *XOFFSET - BSIZE, 0 );
  433.                 arrow_funcs = wlfline;
  434.                 slide_arrow = sliderh;
  435.              }
  436.              break;
  437.                          
  438.     case WA_RTLINE:  if( *FORM_WIDTH > W->work.g_w )
  439.              {
  440.                *XOFFSET += BSIZE;
  441.                *XOFFSET = min( *XOFFSET, *FORM_WIDTH - W->work.g_w );
  442.                arrow_funcs = wrtline;
  443.                slide_arrow = sliderh;
  444.              }    
  445.              break;
  446.                          
  447.            default:
  448.                break;
  449.       }
  450.  
  451.       Graf_mkstate( &m );
  452.       do
  453.       {
  454.          if( arrow_funcs != nada )
  455.          {
  456.            (*arrow_funcs)();
  457.            (*slide_arrow)();
  458.          if( Cur_Handle == WORLD );
  459.                DisplayXY();
  460.            do_redraw( Cur_Handle, &W->work );
  461.      }  
  462.      Graf_mkstate( &m );
  463.       }while( m.buttons ); 
  464.       Graf_mkstate( &m );
  465. }
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472. /* HSlide_Window()
  473.  * ================================================================
  474.  */
  475. void
  476. HSlide_Window( int position )
  477.   if( *FORM_WIDTH > W->work.g_w )
  478.   {
  479.      *XOFFSET = scale( position, *FORM_WIDTH - W->work.g_w, 1000 );
  480.      sliderh();
  481.      if( Cur_Handle == WORLD );
  482.         DisplayXY();
  483.      do_redraw( Cur_Handle, &W->work );
  484.   }  
  485. }
  486.  
  487.  
  488.  
  489.  
  490. /* VSlide_Window()
  491.  * ================================================================
  492.  */
  493. void
  494. VSlide_Window( int position )
  495.   if( *FORM_HEIGHT > W->work.g_h )
  496.   {
  497.      *YOFFSET = scale( position, *FORM_HEIGHT - W->work.g_h, 1000 );
  498.      sliderv();
  499.      if( Cur_Handle == WORLD );
  500.         DisplayXY();
  501.      do_redraw( Cur_Handle, &W->work );
  502.   }  
  503. }
  504.  
  505.  
  506.  
  507. /* Size_Window()
  508.  * ================================================================
  509.  */
  510. void
  511. Size_Window( GRECT *rect )
  512. {
  513.    GRECT prev;
  514.       
  515.    W->r = *rect;
  516.    Wind_get( W->id, WF_PREVXYWH, ( WARGS *)&prev );
  517.    Wind_set( W->id, WF_CURRXYWH, ( WARGS *)&W->r );
  518.    Wind_calc( 1, W->kind, &W->r, &W->work );
  519.    Wind_set( W->id, WF_WORKXYWH, ( WARGS *)&W->work );
  520.    Update_World( Cur_Handle );
  521.    slider_chk();     
  522.  
  523.    if( ( prev.g_w > rect->g_w ) && ( prev.g_h >= rect->g_h ) ||
  524.        ( prev.g_w >= rect->g_w ) && ( prev.g_h > rect->g_h ) )
  525.        do_redraw( Cur_Handle, rect );
  526.        
  527.    if( Cur_Handle == LIBRARY ) /* Used for Full Box of Library Window */
  528.        Old_Lib = W->r;
  529.        
  530.    if( Cur_Handle == WORLD );
  531.       DisplayXY();
  532.        
  533. }                      
  534.  
  535.  
  536. /* Move_Window()
  537.  * ================================================================
  538.  */
  539. void
  540. Move_Window( GRECT *rect )
  541. {
  542.      W->r = *rect;
  543.      Wind_set( W->id, WF_CURRXYWH, ( WARGS *)&W->r );
  544.      Wind_calc( 1, W->kind, &W->r, &W->work );
  545.      Wind_set( W->id, WF_WORKXYWH, ( WARGS *)&W->work );
  546.      Update_World( Cur_Handle );
  547.  
  548.      if( Cur_Handle == LIBRARY )    /* Used for Full Box of Library Window */
  549.      {
  550.         Old_Lib.g_x = W->r.g_x;
  551.         Old_Lib.g_y = W->r.g_y;
  552.      }   
  553. }
  554.  
  555.  
  556.  
  557.  
  558. /* wind_exit();
  559.  * ================================================================
  560.  */
  561. void
  562. wind_exit( void )
  563. {
  564.    int i;
  565.    
  566.    for( i = WORLD; i<= LIBRARY; i++ )
  567.    {
  568.       if( window[i]->id != NO_WINDOW )
  569.                wind_delete( window[i]->id );
  570.       window[i]->id = NO_WINDOW;         
  571.    }
  572. }
  573.  
  574.  
  575.  
  576. /* DaveName()
  577.  * ================================================================
  578.  * Let's Dave pass in a string and change the window title string.
  579.  */
  580. void
  581. DaveName( int id, char *name )
  582. {
  583.    WINFO *x;
  584.  
  585.    x = (( id == WORLD ) ? ( &w ) : ( &l ) );   
  586.    strcpy( x->name, name ); 
  587.    wind_set( x->id, WF_NAME, x->name );
  588. }
  589.  
  590.  
  591.  
  592. /* DaveInfo()
  593.  * ================================================================
  594.  * Let's Dave pass in a string and change the window info string
  595.  * IN: int id    WORLD or LIBRARY
  596.  */
  597. void
  598. DaveInfo( int id, char *name )
  599. {
  600.    WINFO *x;
  601.  
  602.    x = (( id == WORLD ) ? ( &w ) : ( &l ) );   
  603.    strcpy( x->info, name );
  604.    wind_set( x->id, WF_INFO, x->info );
  605. }
  606.  
  607.  
  608.  
  609. /******************************************************************
  610.  * SLIDER CODE for sizing and positioning the vertical and
  611.  * horizontal sliders of a window.
  612.  ******************************************************************/
  613.  
  614.  
  615. /* slider_chk()
  616.  * ================================================================
  617.  * Adjusts the width and height of the sliders.
  618.  * Also, repositions the sliders based on XOFFSET and YOFFSET.
  619.  */
  620. void
  621. slider_chk( void )
  622. {
  623.    wind_set( W->id, WF_VSLSIZE, scale( 1000, W->work.g_h, *FORM_HEIGHT ), 0, 0, 0 );   
  624.    wind_set( W->id, WF_HSLSIZE, scale( 1000, W->work.g_w, *FORM_WIDTH ), 0, 0, 0 );
  625.      
  626.    sliderv();
  627.    sliderh();
  628. }
  629.  
  630.  
  631. /* scale()
  632.  * ================================================================
  633.  * Scaling routine to preserve the fraction.
  634.  */
  635. int
  636. scale( int visible, int factor, int total )
  637. {
  638.    long tmp;
  639.    int  munits;
  640.    long half;
  641.  
  642.    if( total == 0 )    /* just in case of divide by zero...       */
  643.        return( 0 );    /* If this occurs, we have a bug somewhere */
  644.                   /* Cause, the total shouldn't ever be zero */
  645.                   
  646.    half = ((long)total / 2L );
  647.    
  648.    tmp = (long)visible * (long)factor;
  649.    munits = ((tmp % (long)total) > half );
  650.    tmp /= (long)total;
  651.    return( (int)tmp + munits );
  652. }
  653.  
  654.  
  655.  
  656. /* sliderv()
  657.  * ================================================================
  658.  * 
  659.  */
  660. void
  661. sliderv( void )
  662. {
  663.   if( *FORM_HEIGHT < W->work.g_h )    /* the form is smaller than the window*/
  664.       *YOFFSET = 0;
  665.   
  666.   if( *FORM_HEIGHT > W->work.g_h )
  667.       *YOFFSET = min( *YOFFSET, *FORM_HEIGHT - W->work.g_h );
  668.       
  669.   wind_set( W->id, WF_VSLIDE, scale( 1000, *YOFFSET, *FORM_HEIGHT - W->work.g_h ), 0, 0, 0 );
  670. }
  671.  
  672.  
  673. /* sliderh()
  674.  * ================================================================
  675.  */
  676. void
  677. sliderh( void )
  678. {
  679.   if( *FORM_WIDTH < W->work.g_w )
  680.       *XOFFSET = 0;
  681.       
  682.   if( *FORM_WIDTH > W->work.g_w )
  683.      *XOFFSET = min( *XOFFSET, *FORM_WIDTH - W->work.g_w );    
  684.      
  685.   wind_set( W->id, WF_HSLIDE, scale( 1000, *XOFFSET, *FORM_WIDTH - W->work.g_w ), 0, 0, 0 );
  686. }
  687.  
  688.  
  689. /* nada()
  690.  * ================================================================
  691.  */
  692. void
  693. nada( void )
  694. {
  695. }
  696.  
  697.  
  698. /* wupline()
  699.  * ================================================================
  700.  */
  701. void
  702. wupline( void )
  703. {
  704.    *YOFFSET = max( *YOFFSET - BSIZE, 0 );
  705. }
  706.  
  707.  
  708. /* wdnline()
  709.  * ================================================================
  710.  */
  711. void
  712. wdnline( void )
  713. {
  714.    if( *FORM_HEIGHT > W->work.g_h )
  715.    {
  716.       *YOFFSET += BSIZE;
  717.       *YOFFSET = min( *YOFFSET, *FORM_HEIGHT - W->work.g_h );    
  718.    }
  719. }
  720.  
  721.  
  722.  
  723. /* wrtline()
  724.  * ================================================================
  725.  */
  726. void
  727. wrtline( void )
  728. {
  729.  if( *FORM_WIDTH > W->work.g_w )
  730.  {
  731.     *XOFFSET += BSIZE;
  732.     *XOFFSET = min( *XOFFSET, *FORM_WIDTH - W->work.g_w );
  733.  }
  734. }
  735.  
  736.  
  737.  
  738. /* wlfline()
  739.  * ================================================================
  740.  */
  741. void
  742. wlfline( void )
  743. {
  744.    *XOFFSET = max( *XOFFSET - BSIZE, 0 );
  745. }
  746.  
  747.  
  748.  
  749. /* Check_ID()
  750.  * ================================================================
  751.  * Checks the window handle from the system.
  752.  * Returns a oneof our window handles, or -1 ( NO WINDOW ) if
  753.  * its not either one.
  754.  */
  755. int
  756. Check_ID( int id )
  757. {
  758.    int handle = NO_WINDOW;
  759.    
  760.    if( id == window[ WORLD ]->id )
  761.        handle = WORLD;
  762.    
  763.    if( id == window[ LIBRARY ]->id )
  764.        handle = LIBRARY;
  765.    return( handle );    
  766. }
  767.  
  768.  
  769.  
  770. /* SetDave_Stuff()
  771.  * ================================================================
  772.  */
  773. void
  774. SetDave_Stuff( int handle )
  775. {
  776.    Cur_Handle  = handle;
  777.    if( handle != NO_WINDOW )
  778.    {
  779.       W = window[ handle ];
  780.       XOFFSET = &wstruct[ handle ].xoffset;
  781.       YOFFSET = &wstruct[ handle ].yoffset;
  782.       FORM_WIDTH  = &wstruct[ handle ].w_wid;
  783.       FORM_HEIGHT = &wstruct[ handle ].w_hite;
  784.    }
  785. }
  786.  
  787.  
  788.  
  789. /* Set_Window_To_Lynx()
  790.  * ================================================================
  791.  */
  792. void
  793. Set_Window_To_Size( int width, int height  )
  794. {
  795.     GRECT full;
  796.     
  797.     Wind_get( 0, WF_WORKXYWH, ( WARGS *)&full );
  798.  
  799.     wstruct[ WORLD ].xoffset = 0;
  800.     wstruct[ WORLD ].yoffset = 0; 
  801.     w.work.g_w = width;        /* Let's get the work area setup. */
  802.     w.work.g_h = height;
  803.  
  804.     Wind_calc( 0, w.kind, &w.work, &w.r );    /* then calc the actual window*/
  805.     w.r.g_x = full.g_x;
  806.     w.r.g_y = full.g_y;
  807.     w.r.g_w = min( w.r.g_w, full.g_w );
  808.     w.r.g_h = min( w.r.g_h, full.g_h );
  809.     
  810.     Wind_set( w.id, WF_CURRXYWH, ( WARGS *)&w.r );
  811.     Wind_calc( 1, w.kind, &w.r, &w.work );
  812.     Wind_set( w.id, WF_WORKXYWH, ( WARGS *)&w.work );
  813.     SetDave_Stuff( WORLD );
  814.     slider_chk();
  815.     Update_World( WORLD );
  816.     do_redraw( WORLD, &w.work );
  817. }
  818.  
  819.  
  820.  
  821. /* update_world()
  822.  * ================================================================
  823.  */
  824. void 
  825. Update_World( int handle )
  826. {
  827.    wstruct[ handle ].w = window[ handle ]->work;
  828. }
  829.  
  830.  
  831.  
  832.  
  833. int
  834. GetTopWindow( void )
  835. {
  836.    int handle;
  837.    
  838.    wind_get( 0, WF_TOP, &handle );
  839.    
  840.    if( handle == window[ WORLD ]->id )
  841.        return( WORLD );
  842.        
  843.    if( handle == window[ LIBRARY ]->id )
  844.        return( LIBRARY );
  845.        
  846.    return( NO_WINDOW );    
  847. }
  848.  
  849.  
  850.  
  851. /* Allows the user to use the arrow keys to scroll the arrows
  852.  * on a window.
  853.  */
  854. void
  855. do_arrow_buttons( int key )
  856. {
  857.     SetDave_Stuff( GetTopWindow() );
  858.  
  859.     arrow_funcs = nada;
  860.     slide_arrow = sliderv;
  861.  
  862.     switch( key )
  863.     {
  864.        case K_UP:     if( ( *FORM_HEIGHT > W->work.g_h ) && *YOFFSET )
  865.               { 
  866.                  *YOFFSET = max( *YOFFSET - BSIZE, 0 );
  867.                  arrow_funcs = wupline;
  868.               }      
  869.               break;
  870.  
  871.               
  872.        case K_DOWN:   if( *FORM_HEIGHT > W->work.g_h )
  873.                   {
  874.             if( *YOFFSET < ( *FORM_HEIGHT - W->work.g_h ) )
  875.             {
  876.               *YOFFSET += BSIZE;
  877.               *YOFFSET = min( *YOFFSET, *FORM_HEIGHT - W->work.g_h );    
  878.               arrow_funcs = wdnline;
  879.             }  
  880.               }
  881.                      break;
  882.                      
  883.        case K_LEFT:   if( *FORM_WIDTH > W->work.g_w )
  884.               {
  885.                  *XOFFSET = max( *XOFFSET - BSIZE, 0 );
  886.                  arrow_funcs = wlfline;
  887.                  slide_arrow = sliderh;
  888.               }
  889.                      break;
  890.                      
  891.        case K_RIGHT:  if( *FORM_WIDTH > W->work.g_w )
  892.               {
  893.                 *XOFFSET += BSIZE;
  894.                 *XOFFSET = min( *XOFFSET, *FORM_WIDTH - W->work.g_w );
  895.                 arrow_funcs = wrtline;
  896.                 slide_arrow = sliderh;
  897.               }
  898.                      break;
  899.     }
  900.     
  901.     if( arrow_funcs != nada )
  902.     {
  903.        (*arrow_funcs)();
  904.        (*slide_arrow)();
  905.        if( Cur_Handle == WORLD );
  906.              DisplayXY();
  907.        do_redraw( Cur_Handle, &W->work );
  908.     }
  909.     EatKeyboard();  
  910. }
  911.